package com.qs.security.custom;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * 自定义类实现UserDetailsService接口loadUserByUsername方法
 *
 * @author qinyupeng
 * @since 2020-12-18 10:17:05
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        MyUserDetails userDetails = null;
        if ("admin".equals(username)) {
            userDetails = new MyUserDetails(username, passwordEncoder.encode("000000"));
        }

        return userDetails;
    }
}
